<template>
	<view class="card-style">
		<slot name="header"></slot>
		<view style="display: flex;flex-direction: row;">
			<image :src="showImage" style="height: 80px;width: 100px;" v-if="mode==2" @error="handleImageError()"></image>
			<text class="title-box">{{ title }}</text>
		</view>
		<view class="tips-box">
			<text class="top-tag" v-if="isTop">置顶</text>
			<text class="author">{{ author }}</text>
			<text class="comments">{{ comments }}评</text>
			<view class="time-wrapper">
				<text class="time">{{ timedata }}</text>
			</view>
		</view>
		<slot name="tips"></slot>
		<slot name="footer"></slot>
	</view>
</template>

<script>
export default {
	name: "CardViewText",
	data() {
		return {
			defaultPic: "/static/defualtpic.png",
			failPic:"/static/failloadpic.png",
			imageError: false
		};
	},
	computed: {
		showImage() {
			if (this.image && this.image[0]) {
				if (this.imageError) {
					console.log("showImage Error-->" + this.title);
					return this.defaultPic;
				}
				return this.image[0];
			} else {
				console.log("showImage default-->" + this.title);
				return this.defaultPic;
			}
		}
	},
	props: {
		title: {
			type: String,
			default: "新闻标题",
			required: true
		},
		isTop: {
			type: Boolean,
			default: false
		},
		author: {
			type: String,
			default: "来源"
		},
		comments: {
			type: String,
			default: "0"
		},
		timedata: {
			type: String,
			default: "2000.01.01"
		},
		mode: {
			type: Number,
			default: 1, //无图
			required: true
		},
		image: {
			type: Array,
			default: () => []
		},
		showSearch:{
			type:Boolean,
			default:false
		}
	},
	methods: {
		handleImageError(index) {
			console.log("handleImageError--->index" + this.title);
			this.$set(this.images,index, this.imageError);
		}
	}
};
</script>

<style scoped>
.card-style {
	background-color: #fff;
	height: 180rpx;
	padding: 20rpx;
	border-radius: 12rpx;
	box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.1);
}

.title-box {
	font-size: 32rpx;
	font-weight: bold;
	color: #333;
	line-height: 1.4;
}

.tips-box {
	display: flex;
	align-items: center;
	margin-top: 16rpx;
	font-size: 24rpx;
	color: #666;
}

.top-tag {
	color: #f00;
	font-weight: bold;
	margin-right: 16rpx;
}

.author {
	margin-right: 20rpx;
}

.comments {
	margin-right: auto;
}

.time-wrapper {
	display: flex;
	justify-content: flex-end;
}

.time {
	color: #999;
}
</style>